home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-17 | 8.4 KB | 288 lines | [TEXT/MPS ] |
- /*
- File: PCIRoutines.c
-
- Contains: This file contains the routine(s) that are related to the PCI bus.
-
- Written by:
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
-
- To Do:
-
- */
-
- //-----------------------------------------------------------------------------------------
- // Header files
- //-----------------------------------------------------------------------------------------
-
- #include <OpenTptModule.h> // Open Transport files
- #include <OpenTptDevLinks.h>
- #include <Types.h>
-
- #include <Kernel.h> // System files
- #include <DriverServices.h>
- #include <NameRegistry.h>
- #include <Interrupts.h>
- #include <PCI.h>
-
- #include "PCIRoutines.h" // our files
- #include "HWSpecific.h"
-
- //-----------------------------------------------------------------------------------------
- // Global variable for the entire CFM
- //-----------------------------------------------------------------------------------------
-
- extern PortPrivateData *gPortPrivateData; // Declared in ATMDLPI.c
-
- //-----------------------------------------------------------------------------------------
- // Description:
- // This routine extracts the logical address by using the "assigned addresses"
- // property and the "AAPL,address" property. Each card asks the System for certain
- // address spaces depending on their needs. The config space allows for the
- // card to have upto 6 spaces plus a ROM space.
- //
- // This routine accepts as input the offset into config space that matches their
- // space request. In other words, if I am using an Ethernet card it may want two
- // address spaces; I/O and Memory. The card is designed so that offset 0x10 in
- // config space corresponds to the I/O space and 0x14 corresponds to the Memory
- // space.
- //
- // The following values are valid for offsetValues (defined in PCIRoutines.h):
- //
- // #define kPCIConfigBase10Offset 0x10
- // #define kPCIConfigBase14Offset 0x14
- // #define kPCIConfigBase18Offset 0x18
- // #define kPCIConfigBase1COffset 0x1C
- // #define kPCIConfigBase20Offset 0x20
- // #define kPCIConfigBase24Offset 0x24
- // #define kPCIConfigBaseROM30Offset 0x30
- //
- // Input:
- // theID - the NameRegistry ID for a PCI card
- // baseRegAddress - no input value
- // offsetValue - config base offset, determines which address space logically
- // address is returned
- // spaceAllocated - no input value
- //
- // Output:
- // if err = kOTNoError, *baseRegAddress - contains the logical address of a PCI
- // address space, also spaceAllocated is a byte count for the amount of space
- // that was allocated
- // returns various errors
- //
- //-----------------------------------------------------------------------------------------
- OSStatus GetPCICardBaseAddress(RegEntryID *theID, UInt32 *baseRegAddress, UInt8 offsetValue,
- UInt32 *spaceAllocated)
- {
- OSStatus osStatus;
- PCIAssignedAddress *assignedArray;
- RegPropertyValueSize propertySize;
- UInt32 numberOfElements, *virtualArray;
- Boolean foundMatch;
- UInt16 index;
-
- *baseRegAddress = NULL; // default value
- foundMatch = kFalse;
-
- osStatus = GetAProperty(theID, kPCIAssignedAddressProperty,(void **)&assignedArray,
- &propertySize);
-
- if ((osStatus == kOTNoError) && propertySize)
- {
- numberOfElements = propertySize/sizeof(PCIAssignedAddress);
-
- osStatus = GetAProperty(theID, kAAPLDeviceLogicalAddress,(void **)&virtualArray,
- &propertySize);
-
- if ((osStatus == kOTNoError) && propertySize)
- {
- // search through the assigned addresses property looking for base register
- for (index = 0; (index != numberOfElements) && !foundMatch; ++index)
- {
- if (assignedArray[index].registerNumber == offsetValue)
- {
- *spaceAllocated = assignedArray[index].size.lo;
- *baseRegAddress = virtualArray[index];
- foundMatch = kTrue;
- }
- }
- DisposeProperty((void **)&virtualArray);
- }
- else
- osStatus = kENXIOErr;
-
- DisposeProperty((void **)&assignedArray);
- }
- else
- osStatus = kENXIOErr;
-
- return osStatus;
- }
-
- //-----------------------------------------------------------------------------------------
- // Description:
- // This function gets a copy of the property from the tree, allocates memory for it and
- // copies it in. The memory allocation is only valid during non interrupt time!
- //
- // THIS ROUTINE SHOULD ONLY BE CALLED AT NONINTERRUPT TIME
- //
- // Input:
- // theID - the NameRegistry of a device
- // prop - an ascii string name of the property
- // val - address to property value
- // siz - address to size of property
- //
- // Output:
- // returns -1, if the property cannot be returned
- //
- //-----------------------------------------------------------------------------------------
- OSStatus GetAProperty(RegEntryID *theID,RegPropertyName *prop,RegPropertyValue *val,RegPropertyValueSize *siz)
- {
- OSStatus err = kENXIOErr;
-
- err = RegistryPropertyGetSize(theID,prop,siz);
- if (err == noErr)
- {
- *val = PoolAllocateResident(*siz,kTrue);
- if (*val) // did we get the memory that we asked for
- {
- if ((err = RegistryPropertyGet(theID,prop,*val,siz)) != NULL)
- PoolDeallocate(*val);
- }
- }
-
- return err;
- }
-
- //-----------------------------------------------------------------------------------------
- // Description:
- // This routine releases the memory allocated in GetAProperty.
- //
- // Input:
- // val - address of memory that needs to be deallocated
- //
- //
- // Output:
- // NONE
- //
- //-----------------------------------------------------------------------------------------
- void DisposeProperty(RegPropertyValue *val)
- {
- if (*val != NULL)
- PoolDeallocate(*val);
-
- *val = NULL;
- }
-
- //-----------------------------------------------------------------------------------------
- // Description:
- // This routine installs the interrupt service routine for our card.
- //
- // Input:
- // NONE
- //
- // Output:
- // returns error if isr is not installed correctly
- //
- //-----------------------------------------------------------------------------------------
- OSStatus InstallISR(void)
- {
- void *theRefcon;
- InterruptHandler defaultISRFunction;
- InterruptEnabler defaultEnablerFunction;
- InterruptDisabler defaultDisablerFunction;
- OSStatus osStatus;
- RegPropertyValueSize propertySize;
- ISTProperty theISTProperty;
-
- propertySize = sizeof(ISTProperty);
-
- osStatus = RegistryPropertyGet(&gPortPrivateData->nodeEntryID,
- kISTPropertyName,
- &theISTProperty,
- &propertySize);
-
- if (osStatus)
- return osStatus;
-
- osStatus = GetInterruptFunctions(theISTProperty[kISTChipInterruptSource].setID,
- theISTProperty[kISTChipInterruptSource].member,
- &theRefcon,
- &defaultISRFunction,
- &defaultEnablerFunction,
- &defaultDisablerFunction);
-
- if (osStatus == kOTNoError)
- {
- osStatus = InstallInterruptFunctions(theISTProperty[kISTChipInterruptSource].setID,
- theISTProperty[kISTChipInterruptSource].member,
- NULL,
- (InterruptHandler )ABCVendorISR,
- NULL,
- NULL);
-
- if ((osStatus == kOTNoError) && defaultEnablerFunction)
- defaultEnablerFunction(theISTProperty[kISTChipInterruptSource],theRefcon);
- }
-
- return osStatus;
- }
-
- //-----------------------------------------------------------------------------------------
- // Description:
- // This routine uninstalls the interrupt service routine for our card.
- //
- // Input:
- // NONE
- //
- // Output:
- // returns error if problem occurs during uninstall of isr
- //
- //-----------------------------------------------------------------------------------------
- OSStatus UninstallISR(void)
- {
- void *theRefcon;
- InterruptHandler defaultISRFunction;
- InterruptEnabler defaultEnablerFunction;
- InterruptDisabler defaultDisablerFunction;
- OSStatus osStatus;
- RegPropertyValueSize propertySize;
- ISTProperty theISTProperty;
-
- propertySize = sizeof(ISTProperty);
-
- osStatus = RegistryPropertyGet(&gPortPrivateData->nodeEntryID,
- kISTPropertyName,
- &theISTProperty,
- &propertySize);
-
- if (osStatus)
- return osStatus;
-
- osStatus = GetInterruptFunctions(theISTProperty[kISTChipInterruptSource].setID,
- theISTProperty[kISTChipInterruptSource].member,
- &theRefcon,
- &defaultISRFunction,
- &defaultEnablerFunction,
- &defaultDisablerFunction);
-
- if (osStatus == kOTNoError)
- {
- osStatus = InstallInterruptFunctions(theISTProperty[kISTChipInterruptSource].setID,
- theISTProperty[kISTChipInterruptSource].member,
- theRefcon,
- defaultISRFunction,
- defaultEnablerFunction,
- defaultDisablerFunction);
-
- if ((osStatus == kOTNoError) && defaultEnablerFunction)
- defaultDisablerFunction(theISTProperty[kISTChipInterruptSource],theRefcon);
- }
-
- return osStatus;
- }
-
-